package com.scau.XFourPOS.service.impl;

import java.io.Serializable;
import java.util.List;

import org.springframework.transaction.annotation.Transactional;

import com.scau.XFourPOS.dao.BaseDao;
import com.scau.XFourPOS.service.BaseService;
import com.scau.XFourPOS.utils.PageUtils;
/**
 * 基础service 所有service继承该类
 * 提供基础的实体操作方法
 * 使用HibernateDao<T,PK>进行业务对象的CRUD操作,子类需重载getEntityDao()函数提供该DAO.
 * 
 * @param <T>
 * @param <PK>
 */
public abstract class BaseServiceImpl<T> implements BaseService<T>{
	
	/**
	 * 子类需要实现该方法，提供注入的dao
	 * @return
	 */
	public abstract BaseDao<T> getEntityDao();
	
	@Transactional(readOnly = true)
	public T loadEntityById(final Serializable id) {
		return getEntityDao().loadEntityById(id);
	}

	@Transactional(readOnly = false)
	public void saveOrUpdateEntity(final T entity) {
		getEntityDao().saveOrUpdateEntity(entity);;
	}

	@Transactional(readOnly = false)
	public void deleteEntity(final T entity){
		getEntityDao().deleteEntity(entity);
	}
	
	@Transactional(readOnly = false)
	public void deleteEntityById(final Serializable id){
		getEntityDao().deleteEntityById(id);
	}
	
	public PageUtils<T> getAll(final PageUtils<T> page){
		return getEntityDao().getAll(page);
	}
	
	/*@Transactional(readOnly = true)
	public Page<T> search(final Page<T> page, final List<PropertyFilter> filters) {
		return getEntityDao().findPage(page, filters);
	}	*/
}
